// 搜索功能
document.querySelector('.search-input').addEventListener('input', function(e) {
	const searchText = e.target.value.toLowerCase();
	const rows = document.querySelectorAll('tbody tr');

	rows.forEach(row => {
		const name = row.children[1].textContent.toLowerCase();
		row.style.display = name.includes(searchText) ? '' : 'none';
	});
});

// 科目筛选
document.querySelector('.filter-select').addEventListener('change', function(e) {
	const subject = e.target.value;
	const rows = document.querySelectorAll('tbody tr');

	rows.forEach(row => {
		const rowSubject = row.children[2].textContent.toLowerCase();
		if (!subject || rowSubject.includes(subject.toLowerCase())) {
			row.style.display = '';
		} else {
			row.style.display = 'none';
		}
	});
});

// 编辑和删除按钮
document.querySelectorAll('.action-btn').forEach(btn => {
	btn.addEventListener('click', function() {
		const action = this.textContent;
		const row = this.closest('tr');
		const name = row.children[1].textContent;

		if (action === '编辑') {
			alert(`编辑试卷: ${name}`);
		} else if (action === '删除') {
			if (confirm(`确定要删除试卷 ${name} 吗？`)) {
				row.remove();
			}
		}
	});
});

// 分页按钮
document.querySelectorAll('.page-btn').forEach(btn => {
	btn.addEventListener('click', function() {
		if (!this.classList.contains('active')) {
			document.querySelector('.page-btn.active')?.classList.remove('active');
			if (!this.textContent.includes('页')) {
				this.classList.add('active');
			}
		}
	});
});